package com.example.calendar.ui.components

import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

/**
 * Top app bar for the Calendar application.
 *
 * @param title Title to display in the top bar
 * @param showBackButton Whether to show the back button
 * @param showMenuButton Whether to show the menu button
 * @param showMoreOptions Whether to show the more options button
 * @param onNavigateBack Callback when the back button is pressed
 * @param onMenuClick Callback when the menu button is pressed
 * @param onMoreOptionsClick Callback when the more options button is pressed
 */
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun CalendarTopBar(
    title: String,
    modifier: Modifier = Modifier,
    showBackButton: Boolean = false,
    showMenuButton: Boolean = false,
    showMoreOptions: Boolean = false,
    onNavigateBack: () -> Unit = {},
    onMenuClick: () -> Unit = {},
    onMoreOptionsClick: () -> Unit = {}
) {
    TopAppBar(
        title = {
            Text(
                text = title,
                style = MaterialTheme.typography.titleLarge,
                maxLines = 1,
                overflow = TextOverflow.Ellipsis
            )
        },
        navigationIcon = {
            if (showBackButton) {
                IconButton(onClick = onNavigateBack) {
                    Icon(
                        imageVector = Icons.Default.ArrowBack,
                        contentDescription = "Navigate back"
                    )
                }
            } else if (showMenuButton) {
                IconButton(onClick = onMenuClick) {
                    Icon(
                        imageVector = Icons.Default.Menu,
                        contentDescription = "Menu"
                    )
                }
            }
        },
        actions = {
            if (showMoreOptions) {
                IconButton(onClick = onMoreOptionsClick) {
                    Icon(
                        imageVector = Icons.Default.MoreVert,
                        contentDescription = "More options"
                    )
                }
            }
        },
        modifier = modifier,
        colors = TopAppBarDefaults.topAppBarColors(
            containerColor = MaterialTheme.colorScheme.primaryContainer,
            titleContentColor = MaterialTheme.colorScheme.onPrimaryContainer
        )
    )
}

@Preview(showBackground = true)
@Composable
fun CalendarTopBarPreview() {
    MaterialTheme {
        CalendarTopBar(
            title = "Calendar",
            showMenuButton = true,
            showMoreOptions = true
        )
    }
}

@Preview(showBackground = true)
@Composable
fun CalendarTopBarWithBackButtonPreview() {
    MaterialTheme {
        CalendarTopBar(
            title = "Event Details",
            showBackButton = true,
            showMoreOptions = true
        )
    }
} 